<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class mdl_prosedur extends CI_Model {
    
	function __construct(){
        parent::__construct();
    }
	
	function option_proses_penerimaan($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$view_all = isset($d['view_all'])?$d['view_all']:false;
		$out = '';
		
		$this->db->flush_cache();
		if(!$view_all)
			$this->db->where('status', '1');
		$this->db->from('tbl_sd_psb');
		$this->db->order_by('nama_psb');
		
		$res = $this->db->get();
		
		if($view_all)
			$out = '<option value="">-- Pilih --</option>';
			
		foreach($res->result() as $r){
			$out .= '<option value="'.$r->id_psb.'" '.($r->id_psb==$value?'selected="selected"':'').'>'.$r->nama_psb.'</option>';
		}
		
		return $out;
	}
	
	function option_kelompok_penerimaan($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$id_psb = isset($d['id_psb'])?$d['id_psb']:'';
		$view_all = isset($d['view_all'])?$d['view_all']:false;
		$out = '';
		
		$this->db->flush_cache();
		if(!$view_all)
			$this->db->where('status', '1');
		else
			$this->db->where('id_psb', $id_psb);
			
		$this->db->order_by('nama_kelompok');
		
		$res = $this->db->get('tbl_sd_psb_kelompok');

		if($view_all)
			$out = '<option value="">-- Pilih --</option>';
		
		foreach($res->result() as $r){
			$out .= '<option value="'.$r->id_kelompok.'" '.($r->id_kelompok==$value?'selected="selected"':'').'>'.$r->nama_kelompok.'</option>';
		}
		
		return $out;
	}
	
	function option_agama($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$out = '';
		
		$res = array('Islam', 'Kristen', 'Hindu', 'Budha');
		
		//$out = '<option value="">-- Pilih --</option>';
		foreach($res as $r){
			$out .= '<option value="'.$r.'" '.($r==$value?'selected="selected"':'').'>'.$r.'</option>';
		}
		
		return $out;
	}
	
	function option_golongandarah($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$out = '';
		
		$res = array('A', 'B', 'O', 'AB');
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res as $r){
			$out .= '<option value="'.$r.'" '.($r==$value?'selected="selected"':'').'>'.$r.'</option>';
		}
		
		return $out;
	}
	
	function option_status_ortu($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$out = '';
		
		$res = array('Orang Tua Kandung', 'Orang Tua Angkat', 'Orang Tua Tiri');
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res as $r){
			$out .= '<option value="'.$r.'" '.($r==$value?'selected="selected"':'').'>'.$r.'</option>';
		}
		
		return $out;
	}
	
	function option_angkatan($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$out = '';
		
		$this->db->flush_cache();
		$this->db->from('tbl_ref_sd_angkatan');
		$this->db->order_by('angkatan', 'DESC');
		
		$res = $this->db->get();
		
		//$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			$out .= '<option value="'.$r->id_angkatan.'" '.($r->id_angkatan==$value?'selected="selected"':'').'>'.$r->angkatan.'</option>';
		}
		
		return $out;
	}
	
	function option_tahun_ajaran($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$kd_departemen = isset($d['kd_departemen'])?$d['kd_departemen']:'';
		$out = '';
		
		$this->db->flush_cache();
		$this->db->from('tbl_ref_sd_tahunajaran');
		$this->db->where('kd_departemen', $kd_departemen);
		$this->db->order_by('tahunajaran');
		
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			$out .= '<option value="'.$r->id_tahunajaran.'" '.($r->id_tahunajaran==$value?'selected="selected"':'').'>'.$r->tahunajaran.'</option>';
		}
		
		return $out;
	}
	
	function option_tingkat($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$kd_departemen = isset($d['kd_departemen'])?$d['kd_departemen']:'';
		
		$this->db->flush_cache();
		$this->db->from('tbl_ref_sd_tingkat');
		$this->db->order_by('id_tingkat');
		
		//if($kd_departemen !=''){
			$this->db->where('kd_departemen', $kd_departemen);
		// }else{
			// $out = '<option value="">-- Pilih --</option>';
		// }
		
		$res = $this->db->get();
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			if(trim($r->id_tingkat) == trim($value)){
				$out .= '<option value="'.$r->id_tingkat.'" selected="selected">'.$r->tingkat.'</option>';
			}else{
				$out .= '<option value="'.$r->id_tingkat.'">'.$r->tingkat.'</option>';
			}
		}
		
		return $out;
	}
	
	function option_semester($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$id_tingkat = isset($d['id_tingkat'])?$d['id_tingkat']:'';
		
		$this->db->flush_cache();
		$this->db->from('tbl_ref_sd_semester');
		$this->db->order_by('id_semester');
		
		if($id_tingkat !=''){
			$this->db->where('id_tingkat', $id_tingkat);
		}else{
			$out = '<option value="">-- Pilih --</option>';
		}
		
		$res = $this->db->get();
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			if(trim($r->id_semester) == trim($value)){
				$out .= '<option value="'.$r->id_semester.'" selected="selected">'.$r->nama_semester.'</option>';
			}else{
				$out .= '<option value="'.$r->id_semester.'">'.$r->nama_semester.'</option>';
			}
		}
		
		return $out;
	}
	
	function option_tema_by_semester($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$id_semester = isset($d['id_semester'])?$d['id_semester']:'';
		
		$this->db->flush_cache();
		$this->db->from('tbl_ref_sd_tema');
		$this->db->order_by('kd_tema');
		
		if($id_semester !=''){
			$this->db->where('id_semester', $id_semester);
		}else{
			$out = '<option value="">-- Pilih --</option>';
		}
		
		$res = $this->db->get();
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			if(trim($r->kd_tema) == trim($value)){
				$out .= '<option value="'.$r->kd_tema.'" selected="selected">'.$r->nama_tema.'</option>';
			}else{
				$out .= '<option value="'.$r->kd_tema.'">'.$r->nama_tema.'</option>';
			}
		}
		
		return $out;
	}
	
	function option_subtema($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$kd_tema = isset($d['kd_tema'])?$d['kd_tema']:'';
		
		$this->db->flush_cache();
		$this->db->from('tbl_ref_sd_subtema');
		$this->db->order_by('kd_subtema');
		
		if($kd_tema !=''){
			$this->db->where('kd_tema', $kd_tema);
		}else{
			$out = '<option value="">-- Pilih --</option>';
		}
		
		$res = $this->db->get();
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			if(trim($r->kd_subtema) == trim($value)){
				$out .= '<option value="'.$r->kd_subtema.'" selected="selected">'.$r->nama_subtema.'</option>';
			}else{
				$out .= '<option value="'.$r->kd_subtema.'">'.$r->nama_subtema.'</option>';
			}
		}
		
		return $out;
	}
	
	function option_jenis_toaspek($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$out = '';
		
		$this->db->flush_cache();
		$this->db->from('tbl_ref_sd_jenisaspek');
		$this->db->order_by('kd_jenisaspek');
		
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			$out .= '<option value="'.$r->kd_jenisaspek.'" '.($r->kd_jenisaspek==$value?'selected="selected"':'').'>'.$r->kd_jenisaspek.'-'.$r->nama_jenisaspek.'</option>';
		}
		
		return $out;
	}
	
	function option_semester_for_tema($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$out = '';
		
		$this->db->flush_cache();
		$this->db->select('a.*,b.tingkat');
		$this->db->from('tbl_ref_sd_semester a');
		$this->db->join('tbl_ref_sd_tingkat b', 'b.id_tingkat = a.id_tingkat');
		
		$this->db->order_by('a.id_semester');
		
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			$out .= '<option value="'.$r->id_semester.'" '.($r->id_semester==$value?'selected="selected"':'').'>Tingkat '.$r->tingkat.' - '.$r->nama_semester.'</option>';
		}
		
		return $out;
	}
	
	function option_aspek($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$out = '';
		
		$this->db->flush_cache();
		$this->db->from('tbl_ref_sd_sub_aspek');
		$this->db->order_by('kd_aspek');
		
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			$out .= '<option value="'.$r->kd_aspek.'" '.($r->kd_aspek==$value?'selected="selected"':'').'>'.$r->nama_aspek.'</option>';
		}
		
		return $out;
	}
	
	function option_tema($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$out = '';
		
		$this->db->flush_cache();
		$this->db->from('tbl_ref_sd_tema');
		$this->db->order_by('kd_tema');
		
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			$out .= '<option value="'.$r->kd_tema.'" '.($r->kd_tema==$value?'selected="selected"':'').'>'.$r->nama_tema.'</option>';
		}
		
		return $out;
	}
	
	function option_sub_by_tema($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$kd_tema = isset($d['kd_tema'])?$d['kd_tema']:'';
		
		$this->db->flush_cache();
		$this->db->from('tbl_ref_sd_subtema');
		$this->db->order_by('kd_subtema');
		if($kd_tema != ''){
			$this->db->where('kd_tema', $kd_tema);
		}
		//$this->db->where('status', 'A');
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			if(trim($r->kd_subtema) == trim($value)){
				$out .= '<option value="'.$r->kd_subtema.'" selected="selected">'.$r->nama_subtema.'</option>';
			}else{
				$out .= '<option value="'.$r->kd_subtema.'">'.$r->nama_subtema.'</option>';
			}
		}
		
		return $out;
	}
	
	function option_kelas($d=""){
		
	}
	
	/*
	function OptionComboKaryawan($d=""){
		$value = isset($d['value'])?$d['value']:'';
		
		$this->db->flush_cache();
		$this->db->select('a.nip, a.nama, b.jabatan');
		$this->db->from('tbl_pegawai a');
		$this->db->join('tbl_jabatan b', 'a.kd_jabatan=b.kd_jabatan');
		
		$this->db->order_by('a.nama', 'ASC');
		
		$res = $this->db->get();
		
		$out = array();
		$i=0;
		foreach($res->result() as $r){
			$out[$i]['nip'] = $r->nip;
			$out[$i]['nama'] = $r->nama;
			$out[$i]['jabatan'] = $r->jabatan;
			$i++;
		}
		
		return json_encode($out);
	}
	*/
	
	
}

?>